package com.atguigu.controller;

import cn.hutool.core.util.IdUtil;
import com.atguigu.annotations.CustomerLogAnnotation;
import com.atguigu.resp.ResultData;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/aop")
public class CustomerController {

    @GetMapping("/aopTest01")
    public ResultData<String> aopTest01() {

        //添加日志
        System.out.println("方法开始前：添加日志");

        //获取开始时间戳
        long start = System.currentTimeMillis();

        //执行业务逻辑
        String uuid = "";
        try {
            uuid = IdUtil.simpleUUID();
            Thread.sleep(300);
            System.out.println(uuid);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        //获取结束时间戳
        long end = System.currentTimeMillis();

        //添加日志
        System.out.println("方法结束后：添加日志");

        //执行时间
        System.out.println("执行时间：" + (end - start) + "ms");

        //方法返回
        return ResultData.success(uuid);
    }

    @CustomerLogAnnotation(value = "hell", enable = true)
    @GetMapping("/aopTest02")
    public ResultData<String> aopTest02() {

        //执行业务逻辑
        String uuid = IdUtil.simpleUUID();
        System.out.println(uuid);

        //方法返回
        return ResultData.success(uuid);
    }

    @CustomerLogAnnotation(value = "hell", enable = false)
    @GetMapping("/aopTest03")
    public ResultData<String> aopTest03() {

        //执行业务逻辑
        String uuid = IdUtil.simpleUUID();
        System.out.println(uuid);

        //方法返回
        return ResultData.success(uuid);
    }
}
